package com.wl.srb.core.controller.admin;


import com.wl.common.result.R;
import com.wl.srb.core.pojo.entity.IntegralGrade;
import com.wl.srb.core.service.IntegralGradeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 积分等级表 前端控制器
 * </p>
 *
 * @author Helen
 * @since 2021-06-26
 */
@CrossOrigin
@RestController
@RequestMapping("/admin/core/integralGrade")
public class AdminIntegralGradeController {

    @Autowired
    private IntegralGradeService integralGradeService;

    @GetMapping("/list")
    public R listAll(){
        List<IntegralGrade> list = integralGradeService.list();
        return R.ok().data("list",list).message("获取列表成功");
    }

    @DeleteMapping("/remove/{id}")
    public R removeById(@PathVariable Long id){
        boolean b = integralGradeService.removeById(id);
        if(b){
            return R.ok().message("删除成功");
        }
        return R.error().message("删除失败");

    }

    @ApiOperation("新增积分等级")
    @PostMapping("/save")
    public R save(@RequestBody IntegralGrade integralGrade){
        boolean save = integralGradeService.save(integralGrade);
        if(save){
            return R.ok().message("保存成功");
        }
        return R.error().message("保存失败");
    }

    @ApiOperation("根据id获取积分等级")
    @GetMapping("/get/{id}")
    public R getById(@PathVariable Long id){
        IntegralGrade byId = integralGradeService.getById(id);
        if(null != byId){
            return R.ok().data("record",byId);
        }
        return R.error().message("数据获取失败");
    }

    @ApiOperation("更新积分等级")
    @PutMapping("/update")
    public R updateById(@RequestBody IntegralGrade integralGrade){
        boolean save = integralGradeService.updateById(integralGrade);
        if(save){
            return R.ok().message("更新成功");
        }
        return R.error().message("更新失败");
    }

}

